---
title: 自定义钱包
description: 创建一个自定义钱包
---

# 自定义钱包

## 创建一个自定义钱包

> 注意：此API不稳定，并有可能在不久的将来发生变化。我们将逐步增加更多内置钱包。如果有任何特定的钱包感兴趣，请[让我们知道](https://github.com/rainbow-me/rainbowkit/issues) 。

提供`Wallet`函数类型，以帮助您定义自己的自定义钱包。可以在`Wallet`函数的返回值上配置以下属性：

### 钱包属性

<PropsTable
  data={[
    {
      name: 'id',
      required: true,
      type: 'string',
      description: '钱包的唯一 ID',
    },
    {
      name: 'name',
      required: true,
      type: 'string',
      description: '人类可读的钱包名称',
    },
    {
      name: 'rdns',
      required: false,
      type: 'string',
      description: '支持 EIP6963 的钱包的 RDNS',
    },
    {
      name: 'shortName',
      required: false,
      type: 'string | undefined',
      description: '移动端使用的可选短名称',
    },
    {
      name: 'iconUrl',
      required: true,
      type: 'string | (() => Promise<string>)',
      description:
        '钱包图标的网址，或者一个解析为 Base64 数据网址的 promise',
    },
    {
      name: 'iconAccent',
      required: false,
      type: 'string',
      description:
        '在下载流程中用于同时具有浏览器扩展和移动应用程序的钱包的强调色',
    },
    {
      name: 'iconBackground',
      required: true,
      type: 'string',
      description: '钱包图标加载时的背景颜色',
    },
    {
      name: 'installed',
      required: false,
      type: 'boolean | undefined',
      description: (
        <>
            钱包是否已知安装，如果未安装则为 <code>undefined</code>
        </>
      ),
    },
    {
      name: 'downloadUrls',
      required: false,
      type: '{ android?: string, ios?: string, mobile?: string, qrCode?: string, chrome?: string, firefox?: string, edge?: string, safari?: string, opera?: string, browserExtension?: string } | undefined',
      typeSimple: 'DownloadUrls | undefined',
      description: '包含下载网址的对象',
    },
    {
      name: 'hidden',
      required: false,
      type: '(args: { wallets: Array<{ id: string, connector: Connector, installed?: boolean }> }) => boolean',
      typeSimple: '(args) => boolean | undefined',
      description:
        '用于检测这个钱包是否应该从列表中隐藏的函数。这对于定义通用回退钱包很有用,例如内置的 "Injected Wallet" 回退利用了此功能',
    },
    {
      name: 'createConnector',
      required: true,
      type: '() => RainbowKitConnector',
      typeSimple: 'RainbowKitConnector',
      description:
        '提供连接器实例和不同连接方法的配置的函数，如下所述',
    },
    {
      name: 'mobile',
      required: false,
      type: '{ getUri?: (uri: string) => string }',
      typeSimple: 'object',
      description:
        '用于解析移动钱包连接 URI 的函数',
    },
    {
      name: 'desktop',
      required: false,
      type: '{ getUri?: (uri: string) => string }',
      typeSimple: 'object',
      description: '用于解析桌面应用深层链接的函数',
    },
    {
      name: 'qrCode',
      required: false,
      type: "{ getUri: (uri: string) => string, instructions?: { learnMoreUrl: string, steps: Array<{ step: 'install' | 'create' | 'scan', title: string, description: string }> }}}",
      typeSimple: 'object',
      description:
        '包含一个用于解析二维码URI的函数的对象,以及可选的移动钱包设置说明',
    },
    {
      name: 'extension',
      required: false,
      type: "{ instructions?: { learnMoreUrl: string, steps: Array<{ step: 'install' | 'create' | 'scan', title: string, description: string }> }}}",
      typeSimple: 'object',
      description:
        '包含可选的浏览器扩展设置说明的对象',
    },
    {
      name: 'createConnector',
      required: true,
      type: "createConnector: (details: WalletDetailsParams) => CreateConnectorFn",
      typeSimple: '(details: WalletDetailsParams) => CreateConnectorFn',
      description: '提供连接器实例的函数',
    },
  ]}
/>

### 下载网址属性

<PropsTable
  data={[
    {
      name: 'android',
      required: false,
      type: 'string',
      description: 'Google Play 网址',
    },
    {
      name: 'ios',
      required: false,
      type: 'string',
      description: 'Apple App Store 网址',
    },
    {
      name: 'mobile',
      required: false,
      type: 'string',
      description:
        '当 `android` 或 `ios` 不可用时，移动用户的登录页面',
    },
    {
      name: 'qrCode',
      required: false,
      type: 'string',
      description:
        '移动端下载二维码扫描后的登陆页面',
    },
    {
      name: 'chrome',
      required: false,
      type: 'string',
      description: 'Chrome Web Store 网址',
    },
    {
      name: 'edge',
      required: false,
      type: 'string',
      description: 'Microsoft Edge Add-ons 网址',
    },
    {
      name: 'firefox',
      required: false,
      type: 'string',
      description: 'Firefox Browser Add-ons 网址',
    },
    {
      name: 'opera',
      required: false,
      type: 'string',
      description: 'Opera add-ons 网址',
    },
    {
      name: 'safari',
      required: false,
      type: 'string',
      description: 'Mac App Store 网址',
    },
    {
      name: 'browserExtension',
      required: false,
      type: 'string',
      description:
        '当浏览器不兼容某些网址时，桌面扩展用户会看到的登陆页面',
    },
  ]}
/>

### 示例

例如，使用WalletConnect创建一个自定义钱包：

```tsx
import { Wallet, getWalletConnectConnector } from '@rainbow-me/rainbowkit';

export interface MyWalletOptions {
  projectId: string;
}

export const rainbow = ({ projectId }: MyWalletOptions): Wallet => ({
  id: 'my-wallet',
  name: 'My Wallet',
  iconUrl: 'https://my-image.xyz',
  iconBackground: '#0c2f78',
  downloadUrls: {
    android: 'https://play.google.com/store/apps/details?id=my.wallet',
    ios: 'https://apps.apple.com/us/app/my-wallet',
    chrome: 'https://chrome.google.com/webstore/detail/my-wallet',
    qrCode: 'https://my-wallet/qr',
  },
  mobile: {
    getUri: (uri: string) => uri,
  },
  qrCode: {
    getUri: (uri: string) => uri,
    instructions: {
      learnMoreUrl: 'https://my-wallet/learn-more',
      steps: [
        {
          description:
            'We recommend putting My Wallet on your home screen for faster access to your wallet.',
          step: 'install',
          title: 'Open the My Wallet app',
        },
        {
          description:
            'After you scan, a connection prompt will appear for you to connect your wallet.',
          step: 'scan',
          title: 'Tap the scan button',
        },
      ],
    },
  },
  extension: {
    instructions: {
      learnMoreUrl: 'https://my-wallet/learn-more',
      steps: [
        {
          description:
            'We recommend pinning My Wallet to your taskbar for quicker access to your wallet.',
          step: 'install',
          title: 'Install the My Wallet extension',
        },
        {
          description:
            'Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone.',
          step: 'create',
          title: 'Create or Import a Wallet',
        },
        {
          description:
            'Once you set up your wallet, click below to refresh the browser and load up the extension.',
          step: 'refresh',
          title: 'Refresh your browser',
        },
      ],
    },
  },
  createConnector: getWalletConnectConnector({ projectId }),
});
```

然后，您可以在[钱包列表](/docs/custom-wallet-list)中添加您的自定义钱包。
